package me.yuxiaoyao.example.lock.config;

import me.yuxiaoyao.example.lock.response.ApiResponse;
import me.yuxiaoyao.lock.exception.DistributedLockException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author kerryzhang on 2020/12/24
 */


@RestControllerAdvice
public class ExceptionControllerAdvice {
    private static final Logger logger = LoggerFactory.getLogger(ExceptionControllerAdvice.class);


    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    @ExceptionHandler(DistributedLockException.class)
    public ApiResponse<String> distributedLockExceptionHandler(DistributedLockException e) {
        return ApiResponse.<String>with(40000).setMessage("lock failed").setData(e.getMessage()).build();
    }


}
